package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.mapper.HotelClientMessageMapper;
import cn.wolfcode.trip.base.mapper.HotelContentMapper;
import cn.wolfcode.trip.base.mapper.HotelDetailMapper;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelDetailService;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HotelDetailServiceImpl implements IHotelDetailService {

    @Autowired
    private HotelDetailMapper hotelDetailMapper;
    @Autowired
    private HotelContentMapper hotelContentMapper;
    @Autowired
    private HotelClientMessageMapper hotelClientMessageMapper;

    //地区查询的酒店
    @Override
    public List<HotelDetail> insertClientandHotelRegionName(String city,HotelClientMessage hotelClientMessage) {
        List<HotelDetail> hotelDetails = null;
        if (city != null){
            //城市查询
            hotelDetails = hotelDetailMapper.selectHotelDetailByHotelRegionName(city);
        }
        if (hotelClientMessage.getCheckintime()!=null && hotelClientMessage.getCheckouttime()!=null){
            //如果登陆了,session里面有值,添加客户名字保存入住日期和离店日期 保存
            if (UserContext.getCurrentUser() != null) {
                User user = UserContext.getCurrentUser();
                hotelClientMessage.setUser(user);
                Long userId = user.getId();
                //查询该登陆用户所有的酒店为null的订单记录,
                List<HotelClientMessage> hotelClientMessage1 = hotelClientMessageMapper.selectUserRecordByUserId(userId,null);
                //如果该用户没有记录
                if (hotelClientMessage1.size() == 0) {
                    //添加这条记录
                    hotelClientMessageMapper.insert(hotelClientMessage);

                }else{
                    //如果有酒店的数据不等于null
                        //删除掉酒店记录为null的
                        hotelClientMessageMapper.deleteHotelByIsNull(null);
                        //再添加记录
                        hotelClientMessageMapper.insert(hotelClientMessage);
                    }
                }
            }
        return hotelDetails;
    }
    //推荐的酒店
    @Override
    public List<HotelDetail> getHotelDetailByHotelRecommend(int state) {
        return hotelDetailMapper.selectHotelRecommend(state);
    }



    @Override
    public List<HotelDetail> getHotelDetails(Long id) {
        List<HotelDetail> hotelDetails = hotelDetailMapper.selectHotelDetailsByHotelDetailsId(id);
        return hotelDetails;
    }

    //找到文章中的点赞数
    @Override
    public HotelDetail selectHotel(Long id) {
        return hotelDetailMapper.selectByPrimaryKey(id);
    }
    //更新酒店的点赞数
    @Override
    public void updateHotelLikeRecord(HotelDetail hotelDetail) {
        hotelDetailMapper.updateLikeCount(hotelDetail);
    }


    //获取总点赞数
    @Override
    public int getLikeSum(Long id) {
        return hotelDetailMapper.selectLikeSum(id);
    }

    //获取浏览记录
    @Override
    public int getPageView(Long hid) {
        return hotelDetailMapper.selectPageView(hid);
    }

    @Override
    public HotelDetail getPageViewAndId(Long hid) {
        return hotelDetailMapper.selectPageViewAndId(hid);
    }

    @Override
    public void updatePageview(HotelDetail pageViewAndId) {
        hotelDetailMapper.updatePageview(pageViewAndId);
    }



}
